<?php
class DangkyController extends UngvienCController {

    public function accessRules() {
        return array('allow', 'actions' => array('captcha'), 'users' => array('*'));
    }

    public function actionIndex() { 
         //check login
        $uid = Yii::app()->user->getState('info_ungvien')->id;
        if($uid)
           $this->redirect (Yii::app()->getBaseUrl(true).'/ungvien/mykiemviec.html');
        
        //add script
        Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/hoso.css');
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/themes/sysadmin/assets/js/bootstrap-datepicker.js', CClientScript::POS_HEAD);
        Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/themes/sysadmin/assets/css/datepicker.css');
        
        
        $model = new UngvienDangkyForm();
        $this->setPageTitle('Sunghiep.vn | Việc làm online - Tuyển dụng online');
        
        if (isset($_POST['UngvienDangkyForm'])) {
            $model->attributes = $_POST['UngvienDangkyForm'];
            
            if ($model->validate()){
                
               $value = $_POST['UngvienDangkyForm'];
               $ungvien = new Nguoitimviec;
               
               $ungvien->tendangnhap = $value['tendangnhap'];
               $ungvien->matkhau = md5($value['matkhau']);
               $ungvien->email = $value['email'];
               $ungvien->tengoi = $value['tengoi'];
               $ungvien->ngaysinh = $this->convert_date($value['ngaysinh']);
               $ungvien->thanhpho_id = $value['thanhpho'];
               $ungvien->gioitinh = $value['gioitinh'];
               $ungvien->active_code = md5(time()); 
               
               if($ungvien->save()){
                   Yii::app()->user->setFlash('success', '<strong>Chúc mừng!</strong> Đăng ký tài khoản người tìm việc thành công.....');
                   $this->redirect(Yii::app()->getBaseUrl(true));
               }
                   
            }
        }

        $this->render('form', array('model' => $model));
        
    }

    public function actions() {

        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
        );
    }

    public function actiongetThanhpho(){
        
        $thanhpho = Thanhpho::model()->findAllByAttributes(array('quocgia_id' => $_POST['quocgia_id']));
        $thanhphos ='';
        if(count($thanhpho) > 0){
            foreach($thanhpho as $value){
                $thanhphos .= '<option value="'.$value->id.'">'.$value->name.'</option>';
            }               
            echo $thanhphos;
            
        }
        die();
    }

}
?>
